package tree.递归;

import po.TreeNode;

/**
 * @author songZiHao
 * @version 1.0.0
 * @ClassName 对称二叉树101.java
 * @Description TODO https://leetcode-cn.com/problems/symmetric-tree/
 * @createTime 2021年03月26日 11:27:00
 */
public class 对称二叉树101 {

    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        return validate(root.left, root.right);
    }

    private boolean validate(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        if (left == null || right == null) {
            return false;
        }
        if (left.val != right.val) {
            return false;
        }
        return validate(left.right, right.left) && validate(right.right, left.left);
    }
}
